package com.xiyuan.almighty.service;

/**
 * @创建人 袁继鑫
 * @创建时间 2021-04-07 14:05
 * @版本 1.0
 * @描述
 */
public class TestNumberCharPrint {
    public static void main(String[] args) {
        final Object obj = new Object();
        new Thread(() -> {
            synchronized (obj) {
                for (int i = 1; i <= 52; i++) {
                    System.out.println("i = " + i);
                    if (i % 2 == 0) {
                        obj.notifyAll();//释放字母线程
                        try {
                            if (i != 52) obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }, "线程A").start();

        new Thread(() -> {
            for (char i = 'A'; i <= 'Z'; i++) {
                synchronized (obj) {
                    System.out.println("i = " + i);
                    obj.notifyAll();//释放数字线程
                    try {
                        if (i != 'Z') obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "线程B").start();

    }
}
